package com.wormhole.wormholemanagement.utils;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

@Component
public class SecurityUtils {

    public static Long getCurrentOperatorId() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        System.out.println("Authentication有木有: " + authentication.getPrincipal());
        if (authentication != null && authentication.getPrincipal() instanceof OperatorDetails) {
            return ((OperatorDetails) authentication.getPrincipal()).getOperatorId();
        }
        throw new RuntimeException("无法获取当前操作员信息");
    }
}